package com.nuanshui.heatedloan.msgcenter.apppush.filter;

import com.alibaba.fastjson.JSON;
import com.nuanshui.framework.utils.LogUtil;
import com.nuanshui.heatedloan.msgcenter.apppush.annotation.AppPushFilterProvider;
import com.nuanshui.heatedloan.msgcenter.apppush.bean.AppPushResult;
import com.nuanshui.heatedloan.msgcenter.apppush.bean.Invoker;
import com.nuanshui.heatedloan.msgcenter.apppush.bean.ThirdPartyPushResult;
import com.nuanshui.heatedloan.msgcenter.integration.AppPushMsgBody;
import com.nuanshui.heatedloan.msgcenter.model.AppPushMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 日志记录
 * @param 
 * @author guohao
 * @date 2017年1月12日 下午5:00:28
 * @since $
 */
@AppPushFilterProvider(value="loggingFilter",order=99)
public class LoggingFilter implements AppPushFilter {

	private Logger logger = LoggerFactory.getLogger("app_push");
	@Override
	public AppPushResult invoke(Invoker invoker, AppPushMessage appPushMessage) {
		
		LogUtil.info(logger,"-------------------app推送----------------");
		
		LogUtil.info(logger, "推送环境 "+appPushMessage.getMsgBody().getEnv());
		AppPushResult appPushResult =  invoker.doInvoker(appPushMessage);
		
		if(appPushResult.isSuccess()) {
			
			LogUtil.info(logger,"-------------------app推送成功----------------");			
			
		}else {
			LogUtil.info(logger,"-------------------app推送失败----------------");
		}
		List<AppPushMsgBody> list =  appPushResult.getMsgs();
		for(AppPushMsgBody result :list) {
			LogUtil.info(logger, "第三方返回信息  "+result.getResultMsg());
			LogUtil.info(logger,"推送结果  " +JSON.toJSONString(result));
		}
		LogUtil.info(logger,"-------------------app推送结束----------------");
	    return appPushResult;
	}

}
